local base = piece "base"
local pannel1 = piece "pannel1"
local pannel2 = piece "pannel2"
local turret = piece "turret"
local cylinder = piece "cylinder"
local canonbase = piece "canonbase"
local canon = piece "canon"
local slider1 = piece "slider1"
local slider2 = piece "slider2"
local focal1 = piece "focal1"
local focal2 = piece "focal2"
local wheel1 = piece "wheel1"
local wheel2 = piece "wheel2"

local function Slide()
	while( true ) do
		Move(slider1, z_axis, math.random(-9,9), 5)
		WaitForMove(slider1, z_axis)
		Move(slider2, z_axis, math.random(-9,9), 5)
		WaitForMove(slider2, z_axis)
		Sleep(100)
	end
end

local function Initialize()
	Signal(1)
	SetSignalMask(2)

	Spin(wheel1, x_axis, 0.4, 0.1)
	Spin(wheel2, x_axis, 0.4, 0.1)

	Spin(focal1, y_axis, 1, 0.1)
	Spin(focal2, y_axis, -1, 0.1)

	Turn(pannel1, z_axis, -1, 0.2)
	Turn(pannel2, z_axis, 1, 0.2)

	Move(turret, y_axis, 30, 2)
	Spin(canonbase, y_axis, -0.5, 0.1)
	Move(canon, y_axis, 7, 2)
	Sleep(10000)
	Spin(cylinder, y_axis, 0.5, 0.1)

	StartThread(Slide)
end

local function Deinitialize()
	Signal(2)
	SetSignalMask(1)

	StopSpin(wheel1, x_axis, 0.01)
	StopSpin(wheel2, x_axis, 0.01)

	StopSpin(focal1, y_axis, 0.01)
	StopSpin(focal2, y_axis, 0.01)

        Move(turret, y_axis, 0, 2)
        StopSpin(cylinder, y_axis, 0.01)

        StopSpin(canonbase, y_axis, 0.01)
        Move(canon, y_axis, 0, 2)

        Turn(pannel1, z_axis, 0, 0.1)
        Turn(pannel2, z_axis, 0, 0.1)
end

function script.Activate ( )
	StartThread(Initialize)
end

function script.Deactivate ( )
	StartThread(Deinitialize)

end
